//
//  MoveGuideView.m
//  SHHCPhone
//
//  Created by gfsh on 14-6-22.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "MoveGuideView.h"
#import "MoveGuideCell.h"

@implementation MoveGuideView
{
    UILabel *yearNumLab;
    UILabel *monthNumLab;
    UILabel *dayNumLab;
    
    UIScrollView *mainScroll;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *timeBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 66)];
        timeBg.backgroundColor = GET_COLOR(@"feb6d3");
        [self addSubview:timeBg];
        
        UIImageView *timeIV = [[UIImageView alloc]initWithFrame:CGRectMake(19, 66/2-35/2, 35, 35)];
        timeIV.image = [UIImage imageNamed:@"运动指导页-时间icon"];
        [timeBg addSubview:timeIV];
        
        UIView *timeLine = [[UIView alloc]initWithFrame:CGRectMake(19+35/2, timeIV.frame.origin.y+timeIV.frame.size.height-2, 2, 66/2-35/2+2)];
        timeLine.backgroundColor = GET_COLOR(@"ffffff");
        [timeBg addSubview:timeLine];
        
        yearNumLab = [[UILabel alloc]initWithFrame:CGRectMake(70, 0, 54, 66)];
        yearNumLab.textAlignment = NSTextAlignmentCenter;
        yearNumLab.textColor = GET_COLOR(@"ffffff");
        yearNumLab.font = [UIFont boldSystemFontOfSize:19];
        [timeBg addSubview:yearNumLab];
        
        UILabel *yearLab = [[UILabel alloc]initWithFrame:CGRectMake(124, 0, 24, 66)];
        yearLab.textAlignment = NSTextAlignmentCenter;
        yearLab.textColor = GET_COLOR(@"ffffff");
        yearLab.font = [UIFont systemFontOfSize:19];
        yearLab.text = @"年";
        [timeBg addSubview:yearLab];
        
        monthNumLab = [[UILabel alloc]initWithFrame:CGRectMake(148, 0, 35, 66)];
        monthNumLab.textAlignment = NSTextAlignmentCenter;
        monthNumLab.textColor = GET_COLOR(@"ffffff");
        monthNumLab.font = [UIFont boldSystemFontOfSize:19];
        [timeBg addSubview:monthNumLab];
        
        UILabel *monthLab = [[UILabel alloc]initWithFrame:CGRectMake(183, 0, 24, 66)];
        monthLab.textAlignment = NSTextAlignmentCenter;
        monthLab.textColor = GET_COLOR(@"ffffff");
        monthLab.font = [UIFont systemFontOfSize:19];
        monthLab.text = @"月";
        [timeBg addSubview:monthLab];
        
        dayNumLab = [[UILabel alloc]initWithFrame:CGRectMake(207, 0, 35, 66)];
        dayNumLab.textAlignment = NSTextAlignmentCenter;
        dayNumLab.textColor = GET_COLOR(@"ffffff");
        dayNumLab.font = [UIFont boldSystemFontOfSize:19];
        [timeBg addSubview:dayNumLab];
        
        UILabel *dayLab = [[UILabel alloc]initWithFrame:CGRectMake(242, 0, 24, 66)];
        dayLab.textAlignment = NSTextAlignmentCenter;
        dayLab.textColor = GET_COLOR(@"ffffff");
        dayLab.font = [UIFont systemFontOfSize:19];
        dayLab.text = @"日";
        [timeBg addSubview:dayLab];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(19+35/2, timeBg.frame.origin.y+timeBg.frame.size.height, 2, self.frame.size.height-(timeBg.frame.origin.y+timeBg.frame.size.height))];
        line.backgroundColor = GET_COLOR(@"f6f6f6");
        [self addSubview:line];
        
        mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 66, self.frame.size.width, self.frame.size.height-66)];
        [mainScroll setBackgroundColor:[UIColor clearColor]];
        [self addSubview:mainScroll];
        [mainScroll setShowsHorizontalScrollIndicator:NO];
        [mainScroll setShowsVerticalScrollIndicator:NO];
        
//        _circleIV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 16*3/2-14/2, 14, 14)];
//        _circleIV.image = [UIImage imageNamed:@"菜品名称页-圆圈icon"];
        
        
    }
    return self;
}

- (void)setDate:(NSDate *)date
{
    if (date) {
        NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
        NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
        NSDate *now = [NSDate date];
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents *comps = [calendar components:unitFlags fromDate:now];
        int day = [comps day];
        int month = [comps month];
        int year = [comps year];
        yearNumLab.text = [NSString stringWithFormat:@"%d",year];
        monthNumLab.text = [NSString stringWithFormat:@"%d",month];
        dayNumLab.text = [NSString stringWithFormat:@"%d",day];
    }
}

- (void)setCells:(NSArray *)cells
{
    CGFloat height = 12.f;
    for (MoveGuideCell *mgc in cells) {
        mgc.frame = CGRectMake(19+35/2-14/2+1, height, mgc.frame.size.width, mgc.frame.size.height);
        [mainScroll addSubview:mgc];
        height = mgc.frame.origin.y+mgc.frame.size.height;
    }
    MoveGuideCell *mgc = [cells lastObject];
    mainScroll.contentSize = CGSizeMake(self.frame.size.width, mgc.frame.origin.y+mgc.frame.size.height);
}

@end
